from os.path import join
import os

env = Environment(tools=[],ENV=os.environ)
if env['PLATFORM'] == 'win32':
   env.Tool('mingw')
else:
   env.Tool('default')
env.Tool('qt4')
env.EnableQt4Modules(['QtCore','QtNetwork'])
env.Tool('qrs')
env['CXXFILESUFFIX']='.cpp'

vars = Variables('%s_build.conf'%env['PLATFORM'])
vars.Add('CCFLAGS','Custom C compiler flags','')
vars.Add('CPPFLAGS','Custom C/C++ preprocessor flags','')
vars.Add('CXXFLAGS','Custom C++ compiler flags','')
vars.Add('LINKFLAGS','Custom linker flags','')
vars.Add('QRemoteSignal','QRemoteSignal library path. Live blank to detect it using pkg-config','')
vars.Update(env)
# Hack: need to convert flags lists from strings to lists
env['CCFLAGS'] = Split(env['CCFLAGS'])
env['CPPFLAGS'] = Split(env['CPPFLAGS'])
env['CXXFLAGS'] = Split(env['CXXFLAGS'])
env['LINKFLAGS'] = Split(env['LINKFLAGS'])
vars.Save('%s_build.conf'%env['PLATFORM'],env)
Help(vars.GenerateHelpText(env))

try:
   if env['QRemoteSignal'] != '':
      env.Append( LIBPATH=join(env['QRemoteSignal'],'lib') )
      env.Append( CPPPATH=join(env['QRemoteSignal'],'include') )
      env.Append( CPPPATH=join(env['QRemoteSignal'],'include','qremotesignal') )
   else:
      env.ParseConfig('pkg-config --libs --cflags QRemoteSignal')
except OSError: pass

if  not (ARGUMENTS.get('nocheck') or GetOption('clean') or GetOption('help') ) :
   conf = Configure(env)
   if not conf.CheckCXX(): Exit(1)
   if not conf.CheckCXXHeader('QtCore'): Exit(1)
   if not conf.CheckCXXHeader('QtNetwork'): Exit(1)
   if not conf.CheckLibWithHeader('QRemoteSignal','QRemoteSignal','c++'): Exit(1)
   conf.Finish()

Export('env')

Subdirs=['print','hello']

for example in Subdirs:
   SConscript(join(example,'SConscript'))